package com.zxy.ziems.server.scene.convertor;

import com.zxy.ziems.server.file.entity.FileEntity;
import com.zxy.ziems.server.file.vo.FileVO;
import com.zxy.ziems.server.scene.pojo.bo.Frame;
import com.zxy.ziems.server.scene.pojo.dto.SceneDTO;
import com.zxy.ziems.server.scene.pojo.entity.SceneEntity;
import com.zxy.ziems.server.scene.pojo.enums.SceneType;
import com.zxy.ziems.server.scene.pojo.vo.SceneTreeAlarmVO;
import com.zxy.ziems.server.scene.pojo.vo.SceneTreeVO;
import com.zxy.ziems.server.scene.pojo.vo.SceneVO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers;

import java.util.List;

/**
 * @author chdzq
 * @create 2023/3/21
 */
@Mapper(uses = {SceneType.class, FileVO.class})
public interface SceneConvertor {
    SceneConvertor INSTANCE = Mappers.getMapper(SceneConvertor.class);

    @Mapping(target = "frameX", source = "frame.x")
    @Mapping(target = "frameY", source = "frame.y")
    @Mapping(target = "frameZ", source = "frame.z")
    @Mapping(target = "frameWidth", source = "frame.width")
    @Mapping(target = "frameHeight", source = "frame.height")
    SceneEntity sceneDTOConvert2DO(SceneDTO dto);

    List<SceneVO> sceneDOListConvert2OverviewList(List<SceneEntity> list);

    @Mapping(target = "id", source = "entity.id")
    @Mapping(target = "name", source = "entity.name")
    @Mapping(target = "parentId", source = "entity.parentId")
    @Mapping(target = "type", source = "entity.type")
    @Mapping(target = "frame", source = "entity")
    SceneVO sceneDOAndFileConvert2VO(SceneEntity entity, FileVO file);

    @Mapping(target = "id", source = "entity.id")
    @Mapping(target = "name", source = "entity.name")
    @Mapping(target = "parentId", source = "entity.parentId")
    @Mapping(target = "type", source = "entity.type")
    @Mapping(target = "frame", source = "entity")
    SceneTreeVO sceneDOConvert2TreeVO(SceneEntity entity, FileEntity file);

    @Mapping(target = "frame", source = "entity")
    SceneVO sceneDoConvert2VO(SceneEntity entity);

    @Mapping(target = "id", source = "entity.id")
    @Mapping(target = "name", source = "entity.name")
    @Mapping(target = "parentId", source = "entity.parentId")
    @Mapping(target = "type", source = "entity.type")
    @Mapping(target = "frame", source = "entity")
    SceneVO sceneDoConvert2VO(SceneEntity entity, FileEntity file);


    @Mapping(target = "x", source = "frameX")
    @Mapping(target = "y", source = "frameY")
    @Mapping(target = "z", source = "frameZ")
    @Mapping(target = "width", source = "frameWidth")
    @Mapping(target = "height", source = "frameHeight")
    Frame sceneDoConvert2Frame(SceneEntity entity);

    @Mapping(target = "id", source = "entity.id")
    @Mapping(target = "name", source = "entity.name")
    @Mapping(target = "parentId", source = "entity.parentId")
    @Mapping(target = "type", source = "entity.type")
    @Mapping(target = "frame", source = "entity")
    SceneTreeAlarmVO sceneDOConvert2TreeAlarmVO(SceneEntity entity, FileEntity file);
}
